﻿using System.Windows;
using System.Windows.Controls;
using ImageAppViewModels;
using Stats.Plugin;

namespace Stats.Plugin
{
    /// <summary>
    /// Interaction logic for ThumbnailCollectionStatsView.xaml
    /// </summary>
    public partial class ThumbnailCollectionStatsView : UserControl
    {
        public static readonly DependencyProperty ThumbnailCollectionStatsViewModelProperty =
            DependencyProperty.Register("ThumbnailCollectionStatsViewModel", typeof(ThumbnailCollectionStatsViewModel), typeof(ThumbnailCollectionStatsView), new PropertyMetadata(null, OnThumbnailCollectionStatsViewModelPropertyChanged));

        public ThumbnailCollectionStatsViewModel ThumbnailCollectionStatsViewModel
        {
            get { return (ThumbnailCollectionStatsViewModel)GetValue(ThumbnailCollectionStatsViewModelProperty); }
            set { SetValue(ThumbnailCollectionStatsViewModelProperty, value); }
        }

        private static void OnThumbnailCollectionStatsViewModelPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ThumbnailCollectionStatsView source = d as ThumbnailCollectionStatsView;
            source.UpdateThumbnailCollectionStatsViewModel(e.NewValue as ThumbnailCollectionStatsViewModel);
        }

        private void UpdateThumbnailCollectionStatsViewModel(ThumbnailCollectionStatsViewModel ViewStats)
        {
            ThumbnailCollectionStatsViewModel = ViewStats;

            // Let the UI bind to the view-model.
            this.DataContext = ThumbnailCollectionStatsViewModel;
        }
        
        public ThumbnailCollectionStatsView()
        {
            InitializeComponent();
        }        
    }
}
